import scrapy
from bs4 import BeautifulSoup

class PhoneSpider(scrapy.Spider):
    name = "phone_spider"
    start_urls = [
        "https://www.gsmarena.com/"
    ]

    def parse(self, response):
        soup = BeautifulSoup(response.text, "html.parser")
        # 你可以根据具体的页面结构来提取上市时间
        for phone in soup.find_all("div", class_="list-item"):
            title = phone.find("a", class_="name")
            if title:
                phone_name = title.get_text()
                listing_time = self.extract_listing_time(phone_name)
                yield {"phone_name": phone_name, "listing_time": listing_time}

    def extract_listing_time(self, phone_name):
        # 假设页面中会有类似 "上市时间" 关键字，我们可以根据产品名称来提取时间
        # 这里需要根据实际页面的结构调整
        return "2023年12月"
